<?php
class Cts_Db_Login extends Cts_Db_Table
{
    protected $_name = 'cts_login' ;
    protected $_primary = 'id' ;
    
    public function checkUserLogin( $strLoginName , $strPassword )
    {
        $strLoginName = strtolower( trim( $strLoginName ) ) ;
        $strPassword =  md5( trim( $strPassword ) ) ;
        $objSelect = $this->_db->select() ;
        $objSelect->from( $this->_name , '*' )
                  ->where( 'login = ?' , $strLoginName )
                  ->where( 'password = ?' , $strPassword ) ; 
        $strSql = $objSelect->__toString() ;
        $aResult = $this->_db->fetchRow( $strSql ) ; 
        return $aResult ;   
    }
    
    public function getUserInfoList()
    {
        $objSelect = $this->_db->select() ;
        $objSelect->from( $this->_name , '*' )
                  ->joinleft( 'cts_department' , 'cts_department.id = cts_login.department_id' , array( 'department_name' => 'name' ) )
                  ->joinleft( 'cts_position' , 'cts_position.id = cts_login.position_id' , array( 'position_name' => 'name' ) ) 
                  ->joinleft( 'cts_login as cts_leadership' , 'cts_leadership.id = cts_login.leadership_id' , array( 'leadership_login' => 'login' , 'leadership_name' => 'name' ) ) ;
        $strSql = $objSelect->__toString() ;
        $aResult = $this->_db->fetchAll( $strSql ) ;
        return $aResult ;
    }
}